package com.zerox.service.impl;

import com.zerox.mapper.SysUserMapper;
import com.zerox.pojo.SysUser;
import com.zerox.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @auth 吴志勇
 * @date 2022/11/2 16:05
 */
@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public SysUser login(String username, String password) {

        SysUser sysUser = sysUserMapper.selectByUsername(username);

        if (sysUser == null){
            // 没有这个账号
            return null;
        }

        // 有账号，比较密码
        if (password.equals(sysUser.getPassword())){
            // 密码正确  返回
            return sysUser;
        }

        // 密码不正确  返回
        return null;
    }

    @Override
    public List<SysUser> list(Integer pageNo, Integer pageSize,String realName,Integer roleId) {
        Integer startIndex = (pageNo-1)*pageSize;
        return sysUserMapper.list(startIndex,pageSize,realName,roleId);
    }

    @Override
    public int count(String realName, Integer roleId) {
        return sysUserMapper.count(realName,roleId);
    }

    @Override
    public SysUser selectById(Integer id) {
        return sysUserMapper.selectById(id);
    }

    @Override
    public int add(SysUser sysUser) {
        return sysUserMapper.add(sysUser);
    }

    @Override
    public int delete(Integer id) {
        return sysUserMapper.delete(id);
    }

    @Override
    public int update(SysUser sysUser) {
        return sysUserMapper.update(sysUser);
    }

    @Override
    public SysUser selectByAccount(String account) {
        return sysUserMapper.selectByUsername(account);
    }
}
